﻿using System;

namespace ErikLieben.SharePoint.WebParts
{
    public class Range<T> : IRange<T> where T : IComparable<T>
    {
        private T _start;
        private T _end;

        /// <summary>
        /// Initializes a new instance of the <see cref="Range&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        public Range(T start, T end)
        {
            //ExceptionUtil.ThrowIfTrue<ArgumentException>(start == null, "Parameter {0} cannot be null", "start");
            //ExceptionUtil.ThrowIfTrue<ArgumentException>(end == null, "Parameter {0} cannot be null", "end");
            _start = start;
            _end = end;
        }

        /// <summary>
        /// Determines whether the specified item is within the setup range.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>
        /// 	<c>true</c> if [contains] [the specified item]; otherwise, <c>false</c>.
        /// </returns>
        public Boolean Contains(T item)
        {
            //DebugUtil.ShowDebugWarningIf(item == null, "item argument cannot be null, returning false (does not contain)");
            if (item == null) return false;
            return _start.IsLessThanOrEqualTo(item) && item.IsLessThanOrEqualTo(_end);
        }
    }

}
